﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using log4net;
using log4net.Appender;
using log4net.Core;
using log4net.Layout;
using log4net.Repository.Hierarchy;

namespace Aluetjen.EmailService.Agent
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            var servicesToRun = new [] { new Service1() };

            if(args.Contains("-application"))
            {
                var hierarchy = (Hierarchy) LogManager.GetRepository();
                var consoleAppender = new ConsoleAppender
                                          {
                                              Layout = new PatternLayout("%-4timestamp [%thread] %-5level %logger %ndc - %message%newline")
                                          };
                hierarchy.Root.Level = Level.Warn;
                hierarchy.Root.AddAppender(consoleAppender);

                servicesToRun[0].RunAsConsole(args);
            }
            else
            {
                ServiceBase.Run(servicesToRun);
            }
        }
    }
}
